//
//  LSSocketManeger.h
//  LookScore
//
//  Created by wws on 2018/3/23.
//  Copyright © 2018年 ChongQingXunTiCompany. All rights reserved.
//

#import <Foundation/Foundation.h>
/**socket状态*/
typedef NS_ENUM(NSInteger, LSSocketStatus){
    LSSocketStatusConnected,// 已连接
    LSSocketStatusFailed,// 失败
    LSSocketStatusClosedByServer,// 系统关闭
    LSSocketStatusClosedByUser,// 用户关闭
    LSSocketStatusReceived// 接收消息
};
/**消息类型*/
typedef NS_ENUM(NSInteger ,LSSocketReceiveType) {
    LSSocketReceiveTypeForMessage,
    LSSocketReceiveTypeForPong
    
    
};

/**连接成功回调*/
typedef void (^LSSocketDidConnectBlock)(void);
/**失败回调*/
typedef void (^LSSocketDidFailBlock)(NSError * error);
/**关闭回调*/
typedef void (^LSSocketDidCloseBlock)(NSInteger code, NSString * reason , BOOL wasClean);
/**消息接受回调*/
typedef void (^LSSocketDidReciveBlock)(id message,LSSocketReceiveType type);


@interface LSSocketManeger : NSObject
@property (nonatomic, copy) LSSocketDidConnectBlock connect;
@property (nonatomic, copy) LSSocketDidReciveBlock receive;
@property (nonatomic, copy) LSSocketDidFailBlock failure;
@property (nonatomic, copy) LSSocketDidCloseBlock close;
@property (nonatomic, assign, readonly) LSSocketStatus ls_socketStatus;
/**超时重连时间 默认1秒*/
@property (nonatomic, assign) NSTimeInterval overtime;
/**重连次数 ， 默认5次*/
@property (nonatomic, assign) NSUInteger reconnectCount;

@property (nonatomic, assign) NSUInteger reconnectCounter;

/**单利*/
+ (instancetype)shareManeger;
/**
 *  @author LS
 *
 *  开启socket
 *
 *  @param urlStr  服务器地址
 *  @param connect 连接成功回调
 *  @param receive 接收消息回调
 *  @param failure 失败回调
 */
- (void)ls_open:(NSString *)urlStr connect:(LSSocketDidConnectBlock) connect receive:(LSSocketDidReciveBlock) receive failure:(LSSocketDidFailBlock) failure;
/**
 *  @author LS
 *
 *  关闭socket
 *
 *  @param close 关闭回调
 */
- (void)ls_close:(LSSocketDidCloseBlock)close;
/**
 *  @author LS
 *
 *  发送消息，NSString 或者 NSData
 *
 *  @param data Send a UTF8 String or Data.
 */
- (void)ls_send:(id)data;

@end
